package com.szbber.medical.board.ui.activity

import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.utils.ServiceUtils
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.szbber.commen.service.MqttService
import com.szbber.commen.base.BaseActivity
import com.szbber.commen.base.BaseFragmentPageAdapter
import com.szbber.commen.base.BaseRoutePath
import com.szbber.commen.bean.TabEntity
import com.szbber.commen.utils.CommonUtil
import com.szbber.medical.board.R
import com.szbber.medical.board.ui.fragment.PatientInfoFragment
import com.szbber.medical.board.ui.fragment.ScheduleFragment
import com.szbber.medical.board.ui.fragment.SettingFragment
import kotlinx.android.synthetic.main.board_activity_home.*

@Route(path = BaseRoutePath.board_home)
class HomeActivity : BaseActivity() {

    private var myAdapter: BaseFragmentPageAdapter? = null
    private val mTitleList = ArrayList<String>()
    private val mFragments: ArrayList<Fragment> = ArrayList()
    private val mTabEntities = ArrayList<CustomTabEntity>()

    private val mIconUnselectIds = intArrayOf(
        R.drawable.icon_boardhome_item1_n,
        R.drawable.icon_boardhome_item2_n,
        R.drawable.icon_boardhome_item3_n,
        R.drawable.icon_boardhome_item4_n,
        R.drawable.icon_boardhome_item5_n,
        R.drawable.icon_boardhome_item6_n
    )
    private val mIconSelectIds = intArrayOf(
        R.drawable.icon_boardhome_item1_p,
        R.drawable.icon_boardhome_item2_p,
        R.drawable.icon_boardhome_item3_p,
        R.drawable.icon_boardhome_item4_p,
        R.drawable.icon_boardhome_item5_p,
        R.drawable.icon_boardhome_item6_p
    )

    override fun initLayout(): Int = R.layout.board_activity_home
    override fun initView() {

        mTitleList.add("科室一榄表")
        mTitleList.add("护理信息")
        mTitleList.add("动态床卡")
        //        mTitleList.add("健康宣教")
        //        mTitleList.add("护士排班")
        mTitleList.add("系统")
        tvTitle.text = CommonUtil.getDeptName()
        mTitleList.forEachIndexed { index, s ->
            mTabEntities.add(TabEntity(s, mIconSelectIds[index], mIconUnselectIds[index]))
        }

        tabLayout.setTabData(mTabEntities)
        mFragments.add(ScheduleFragment.getInstance())
        mFragments.add(PatientInfoFragment.getInstance())
        mFragments.add(ScheduleFragment.getInstance())
        mFragments.add(SettingFragment.getInstance())
//        mFragments.add(BoardPatientInfoList.getInstance())
//        mFragments.add(BoardDynamicBedCardFragment.getInstance())
        //        mFragments.add(HealthyFragment.getInstance())
        //        mFragments.add(WorkPlanFragment.getInstance())
//        mFragments.add(SettingFragment.getInstance())
        ServiceUtils.startService(this, MqttService::class.java)
        myAdapter = BaseFragmentPageAdapter(supportFragmentManager, mFragments, mTitleList)
        mViewPager.adapter = myAdapter
        mViewPager.currentItem = 0
        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                mViewPager.currentItem = position
            }
            override fun onTabReselect(position: Int) {}
        })

        mViewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                tabLayout.currentTab = position
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
    }
}